<?php
include '../../init.php';

$action  = @$_POST['action'];

// 顶置
if ($action == 'updateTop') {
	$pid  = $_POST['pid'];
	$value = $_POST['value'];
	$sql  = "UPDATE `post_tb` SET isTop={$value} WHERE pid={$pid}";
	$data = array();
	if (!my_mysql_query($sql, $data)){
		show_msg(1,'顶置失败',3);
		exit();
	}
	if ($value){
		$uid  = $_POST['uid'];
		addscore($uid, 2);
		show_msg(0,'顶置成功',1);
	} else {
		show_msg(0,'取消成功',1);
	}
	exit();
}

// 加精
if ($action == 'updateGood') {
	$pid  = $_POST['pid'];
	$value = $_POST['value'];
	$sql  = "UPDATE `post_tb` SET iswally={$value} WHERE pid={$pid}";
	$data = array();
	if (!my_mysql_query($sql, $data)){
		show_msg(1,'加精失败',3);
		exit();
	}
	if ($value){
		$uid  = $_POST['uid'];
		addscore($uid, 5);
		show_msg(0,'加精成功',1);
	}else{
		show_msg(0,'取消成功',1);
	}
	exit();
}


// 删除
if ($action == 'addDel') {
	$pid  = $_POST['pid'];
	$sql  = "UPDATE `post_tb` SET isDel=1 WHERE pid=".$pid;
	$data = array();
	if (!my_mysql_query($sql, $data)){
		show_msg(1,'删除帖子失败',3);
		exit();
	}
	show_msg(0,'删除帖子成功',1);
	exit();
}



// 查询该用户是否被禁言
$uid  = $_SESSION['uid'];
$data = array();
$sql = "SELECT isStop FROM `login_tb` WHERE uid=".$uid;
my_mysql_query($sql, $data);
if ($data[0]['isStop']){
	show_msg(1,'你被禁言,不能发言,联系管理员',3);
	exit();
}


// 将帖子列表加入到数据库中
$modulID = @$_POST['modulID'];
$content = @$_POST['content'];
if (empty(trim($content))){
	show_msg(1,'内容不能为空',3);
	exit();
}


// 发帖
if ($action == 'post') {
	$title= trim($_POST['title']);
	if (empty($title)){
		show_msg(1,'发帖标题不能为空',3);
		exit();	
	}
	$sql  = "INSERT INTO `post_tb`(modid,uid,title,content,create_time) values ";
	$sql .= "({$modulID},{$uid},'{$title}','{$content}',".time().");";
	$data = array();
	if (!my_mysql_query($sql, $data)){
		show_msg(1,'发帖失败',3);
		exit();
	}
	// 发帖成功获得两个积分
	addscore($uid, 2);
	show_msg(0,'发帖成功,得到2积分',1);
	exit();
}


// 回帖
if ($action == 'revert') {
	$pId  = $_POST['parentId'];
	$sql  = "INSERT INTO `post_tb`(modid,uid,parentId,title,content,create_time) values ";
	$sql .= "({$modulID},{$uid},{$pId},'','{$content}',".time().");";
	$data = array();
	if (!my_mysql_query($sql, $data)){
		show_msg(1,'回帖失败',3);
		exit();
	}
	addscore($uid, 1);
	show_msg(0,'回帖成功,得到1积分',1);
	exit();
}

?>